﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NBlock.MVCExtensions;
using NBlock.Components.Excel;
using NBlock.MVCExtensions;
using NBlock.Core;
using NBlock.Core.ORM;
using System.Linq.Expressions;
using Cost.Models;

namespace Cost.Controllers
{
    public class MaterialOrderItemController : Controller
    {
        private readonly ICostRepository<MaterialOrderItemView> materialorderitemRepository;

        public MaterialOrderItemController(ICostRepository<MaterialOrderItemView> materialorderitemRepository)
        {
            this.materialorderitemRepository = materialorderitemRepository;
        }

        //
        // GET: /DishOrder/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult List(DateTime? date, nbPageInfo pager, nbSearchCondition where)
        {
            var siteId = nbUserContext.Current.CurrentUser.UnitCode;
            Expression<Func<MaterialOrderItemView, bool>> filter = m => m.SiteId == siteId;
            if (date.HasValue)
                filter = filter.And(m => m.Date == date);

            var pageData = materialorderitemRepository.GetPageable(pager, filter, where);
            var data = pager.ToGridData(pageData);
            return Json(data);
        }
    }
}
